package com.stone.design.patterns.state;

/**
 * @author Stone
 * @version V1.0
 * @description:
 * @date 4/25/18 22:03
 * @email redsstone@163.com
 */
public class SoldState implements State{

    GumballMachine mGumballMachine;

    public SoldState(GumballMachine gumballMachine) {
        mGumballMachine = gumballMachine;
    }

    @Override
    public void insertQuarter() {

        System.out.println("please wait, we're already give you gumball");

    }

    @Override
    public void ejectQuarter() {
        System.out.println("sorry, you already turn the crank");
    }

    @Override
    public void tumCrank() {
        System.out.println("turning twice doesn't get you another gumball!");
    }

    @Override
    public void dispense() {
        System.out.println("out ouf gumballs!!!");

        // 根据糖果数量来确定状态
        if (mGumballMachine.getCount() > 0) {
            mGumballMachine.setState(mGumballMachine.getNoQuarterState());
            return;
        }
        mGumballMachine.setState(mGumballMachine.soldOutState);
    }
}
